package fschmidt.util.executor;

import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.BlockingQueue;


public final class ThreadTimer implements RunnableWrapper {
	private final Map<Thread,Date> map = new ConcurrentHashMap<Thread,Date>();

	@Override public Runnable wrap(final Runnable command) {
		return new Runnable(){public void run(){
			map.put(Thread.currentThread(),new Date());
			try {
				command.run();
			} finally {
				map.remove(Thread.currentThread());
			}
		}};
	}

	public Date whenRun(Thread thread) {
		return map.get(thread);
	}

	public Set<Thread> getThreads() {
		return map.keySet();
	}
}
